import time
import requests

print(time.strftime("开始时间：%Y-%m-%d %H:%M:%S"))

try:
    html_str = requests.get('http://www.google.com').text
    print("访问成功")
except requests.exceptions.RequestException as error:
    print(error)

print(time.strftime("结束时间：%Y-%m-%d %H:%M:%S"))    # 等待约20秒


print(time.strftime("开始时间：%Y-%m-%d %H:%M:%S"))

try:                                     # 设置超时时间，减少等待时间
    html_str = requests.get('http://www.google.com', timeout=5).text
    print("访问成功")
except requests.exceptions.RequestException as error:
    print(error)

print(time.strftime("结束时间：%Y-%m-%d %H:%M:%S"))  # 相差5秒
